﻿using XFControls.Utils;
using XFControls.XFPanels.XFPanelItems;
using System.Drawing;

namespace XFSenseUI.XFItems.SenseControls
{
    public class SenseControlDropDown : SenseControl
    {
        public string Text { get; set; }

        public SenseControlDropDown()
        {
            Style = new XFItemStyle
                    {
                        TextFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular),
                        TextColor = Color.Black,
                        Padding = 10
                    };
        }

        public override void OnBlur()
        {
            //Invalidate();
        }

        public override int GetWidth()
        {
            if (ItemRectangle.Width != 0)
                return ItemRectangle.Width;

            ItemRectangle = this.GetImageRec("dropdown");
            return ItemRectangle.Width;
        }

        public override int GetHeight()
        {
            if (ItemRectangle.Height != 0)
                return ItemRectangle.Height;

            ItemRectangle = this.GetImageRec("dropdown");
            return ItemRectangle.Height;
        }

        public override void ItemPaint(Graphics g, int x, int y)
        {
            Rectangle rec = new Rectangle(x, y, ItemRectangle.Width, ItemRectangle.Height);
            DrawUI("dropdown", g, rec, false);

            if (string.IsNullOrEmpty(Text)) return;
            using (SolidBrush b = new SolidBrush(Style.TextColor))
                g.DrawString(Text, Style.TextFont, b, new RectangleF(Style.PaddingLeft + x, Style.PaddingTop + y, ItemRectangle.Width, ItemRectangle.Height));
        }
    }
}
